package com.szgr.baoyin.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.szgr.baoyin.MyApplication;
import com.szgr.baoyin.R;
import com.szgr.baoyin.utils.Constant;

/**
 * 会员章程
 */
public class VipRuleActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_vip_rule);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initActionBar() {
        actionBarTitle.setText("会员条款");
    }

    @Override
    public void initView() {

        View btn_apply = findViewById(R.id.vip_rule_apply_vip);
        View btn_detail = findViewById(R.id.vip_rule_back);
        btn_detail.setOnClickListener(this);
        btn_apply.setOnClickListener(this);

        Intent intent = getIntent();
        if(intent != null && intent.hasExtra("from")){
            btn_apply.setVisibility(View.GONE);
            btn_detail.setVisibility(View.GONE);
        }
        String url = Constant.URL_VIP_02;
        if(intent != null && intent.hasExtra("myself")){
            btn_apply.setVisibility(View.GONE);
            btn_detail.setVisibility(View.GONE);
            url = Constant.URL_VIP_01;
            actionBarTitle.setText("会员手册");
        }

        if(intent != null && intent.hasExtra("open")){
            url = Constant.URL_SETTING;
            btn_apply.setVisibility(View.GONE);
            btn_detail.setVisibility(View.GONE);
            actionBarTitle.setText("配置全公开");
        }

        WebView webView = (WebView) findViewById(R.id.vip_rule_web_view);
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        webView.loadUrl(url);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.vip_rule_back:
                if(MyApplication.getmInstance().isLogin()) {
                    startActivity(new Intent(this, ApplyCardActivity.class));
                }else{
                    startActivity(new Intent(this, LoginActivity.class));
                }
                break;
            case R.id.action_bar_left:
                finish();
                break;
            case R.id.vip_rule_apply_vip:
                Intent intent = new Intent(this, VipRuleActivity.class);
                intent.putExtra("myself","myself");
                startActivity(intent);
                break;
        }
    }
}
